import { CreateOrderRequestType } from "@/types/order";
import { UserAddressType } from "@/types/user";
import httpInstance from "@/utils/http";

// 获取购物车结算详情
export const getCheckInfoAPI = () => {
    return httpInstance({
        method: 'GET',
        url: '/member/order/pre',
    });
};

// 生成订单
export const createOrderAPI = (data: CreateOrderRequestType) => {
    return httpInstance({
        url: '/member/order',
        method: 'POST',
        data,
    });
};

// 添加收货地址
export const createAddressAPI = (data: UserAddressType) => {
    return httpInstance({
        url: '/member/address',
        method: 'POST',
        data,
    });
};

// 获取收货地址
export const getAddressAPI = () => {
    return httpInstance({
        url: '/member/address',
        method: 'GET',
    });
};

// 删除收货地址
export const deleteAddressAPI = (id: string) => {
    return httpInstance({
        url: `/member/address/${id}`,
        method: 'DELETE',
    });
};

// 修改收货地址
export const correctAddressAPI = (id: string, data: UserAddressType) => {
    return httpInstance({
        url: `/member/address/${id}`,
        method: 'PUT',
        data,
    });
};